package com.wcards.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcards.config.R;
import com.wcards.dto.GoodsDTO;
import com.wcards.entity.Goods;
import com.wcards.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("商品模块")
@RestController
@Slf4j
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;


    /*
     商品增加
     */
    @ApiOperation("添加商品")
    @PostMapping("/createGoods")
    public R<String> creatGoods(@RequestBody GoodsDTO goodsDTO) {

        return goodsService.createGoods(goodsDTO);
    }

    /*
    删除商品
    */
    @ApiOperation("删除商品")
    @DeleteMapping("/deleteGoods")
    public R<String> deleteGoods(Integer id) {
        return goodsService.deleteGoods(id);
    }

    /*
     * 商品修改
     * */
    @ApiOperation("商品修改")
    @PutMapping("/updateGoods")
    public R<String> updateGoods(@RequestBody GoodsDTO goodsDTO) {
        return goodsService.updateGoods(goodsDTO);
    }

    /*
     * 查询商品
     * */
    @ApiOperation("查询商品")
    @GetMapping("/findGoods")

    public R<Page<Goods>> findGoods(@RequestBody GoodsDTO goodsDTO, Integer pageSize, Integer pageNumber) {

        return goodsService.findGoods(goodsDTO, pageSize, pageNumber);
    }
}
